package com.api.oa.services.impl;

import cn.hutool.core.date.DateUtil;
import com.api.oa.mapper.YQNewsMapper;
import com.api.oa.model.entity.YQNews;
import com.api.oa.services.YQNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;


@Service
public class YQNewsServiceImpl implements YQNewsService {

    @Autowired
    private YQNewsMapper mapper;


    @Override
    public Integer add(YQNews entity) {
        entity.setCreatedAt(DateUtil.date());
        return mapper.insert(entity);
    }

    @Override
    public void remove(Long id) {
        mapper.delete(id);
    }

    @Override
    public Integer update(YQNews entity) {
        return mapper.update(entity);
    }

    @Override
    public PageInfo<YQNews> list(String keyWord, String newType, Integer pageIndex, Integer pageSize) {
        PageHelper.startPage(pageIndex, pageSize);
        PageHelper.orderBy("newId desc");
        return new PageInfo<>(mapper.list(keyWord, newType));
    }

    @Override
    public YQNews one(Long id) {
        return mapper.findOne(id);
    }


}
